#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;

#define int long long
int T;
int n;
int a[N], c[N];
int ans;
int num[N], last[N];
const int MOD = 1e10;

void work1(){
    int ret = 0;
    for(int col = 0; col < (1 << n); col ++){
        int last1 = -1;
        int last0 = -1;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            int tmp = (1 << i);
            if(col & tmp){//black
                if(last1 == -1){
                    last1 = i;
                    continue;
                }
                if(a[last1] == a[i])
                    cnt += a[i];
                last1 = i;
            }
            else{
                if(last0 == -1){
                    last0 = i;
                    continue;
                }
                if(a[last0] == a[i])
                    cnt += a[i];
                last0 = i;
            }
        }
        // cout << col << " " << ret << endl;
        ret = max(ret, cnt);
    }
    ans = ret;
}

void work2(){
    for(int i = 1; i <= n; i++)
        num[i] = 0;
    // int col[N];
    // memset(col, 0, sizeof col);
    int ret = 0;
    for(int i = 1; i <= n; i++){
        if(num[a[i]] != 0){
            ret = (ret + a[i]) % MOD;
            last[i] = num[a[i]];   
        }
        num[a[i]] = i;
    }
    ans = ret;
}

signed main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while(T --){
        cin >> n;
        int maxn = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            maxn = max(a[i], maxn);
        }
        if(n <= 21)
            work1();
        else if (maxn <= 1e5)
            work2();
        cout << ans << endl;
    }
    
    return 0;
}